const promise = require('bluebird');
const utils = promise
    .promisifyAll(require('/Users/Steve/tools/myGit/xNode/common/FooUtils.js'));
// var token = process.argv[2].trim();

const mustache = require('mustache');

const globalConfigObject = {
    "artifactId": "tenmalife-platform",
    "gitHome": `/Users/Steve/tools/myGit`,
    "mvnBash": `/Users/Steve/tools/apache-maven-3.3.9/bin/mvn`
};

const globalConfigPropertiesFile = '/Users/Steve/tools/myGit/jUtils/src/main/resources/global-config.properties';
const globalConfigJsonFile = '/Users/Steve/tools/myGit/xNode/globalConfig.json';

const globalConfigPropertiesTmpl = `artifactId = {{{artifactId}}}
gitHome = {{{gitHome}}}
mvnBash = {{{mvnBash}}}
`;

utils.renderWithMustacheAsync(__dirname + '/configuration/globalConfig.json.mustache', globalConfigObject).then((data)=> {
    utils.writeFileAsync(globalConfigJsonFile, data);
    utils.writeFileAsync('/Users/Steve/tools/myGit/xNode/globalConfig.json', data);
}).then(()=> {
    console.log(`success write globalConfigJsonFile file in path:${globalConfigJsonFile}`);
}).catch((err) => {
    console.log(`error is:${err}`);
});

const globalConfigPropertiesResult = mustache.render(globalConfigPropertiesTmpl, globalConfigObject);

utils.writeFileAsync(globalConfigPropertiesFile, globalConfigPropertiesResult)
    .then(()=> {
        console.log(`success write globalConfigPropertiesFile file in path:${globalConfigPropertiesFile}`);
    }).catch((err) => {
    console.log(`error is:${err}`);
});

